package pen_exam.danakeji_2023_11_10;


import sun.print.SunMinMaxPage;

import java.util.Scanner;

//n,m 两个数组 长度  两个数组 A，B 在 B 中找子数组离A的和最近
public class Class03_CloseeArr {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        String[] s2 = sc.nextLine().split(" ");
        String[] s3 = sc.nextLine().split(" ");
        int n = Integer.parseInt(s1[0]);
        int m = Integer.parseInt(s1[1]);
        int[] arr2 = new int[m];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += Integer.parseInt(s2[i]);
        }
        for (int i = 0; i < m; i++) {
            arr2[i] = Integer.parseInt(s3[i]);
        }
        if(arr2.length < 2){
            System.out.println(arr2[0]);
        }else{
            int[] res =  process(arr2, sum);
            for (int i = 0; i < 2; i++) {
                System.out.println(res[i]);
            }
        }
    }
    public static int[] process(int[] arr, int sum){
        int L = 0;
        int ans = arr[L];
        int close = Math.abs(sum - arr[L]);
        int[] res = new int[]{arr[L],0};
        for (int R = 1; R < arr.length; R++) {
            ans += arr[R];
            while (ans > sum && L < R){
                ans -= arr[L];
                if(Math.abs(ans - sum) < close){
                    close = Math.abs(ans - sum);
                    res = new int[]{arr[L],arr[R]};
                }
                L++;
            }
            if(Math.abs(ans - sum) < close){
                close = Math.abs(ans - sum);
                res = new int[]{arr[L],arr[R]};
            }
        }
        return res;
    }


}
